import Vue from 'vue'
import VueRouter from 'vue-router'


Vue.use(VueRouter)

const routes = [
  {
    path: '/',
    // component: () => import ('../views/Home.vue')
    redirect: '/home'
  }
  ,
  {
    path: '/home',
    name: 'Home',
    component: () => import ('../views/Home.vue'),
    children: [
      {
        path: '/home/',
        // component: () => import('../home-camp/camp-guanzhu.vue')
        redirect: '/home/camp-guanzhu'
      },
      {
        path: '/home/camp-guanzhu',
        name: 'Guanzhu',
        component: () => import('../home-camp/camp-guanzhu.vue')
      },
      {
        path: '/home/camp-tuijian',
        name: 'Tuijian',
        component: () => import('../home-camp/camp-tuijian.vue')
      },
      {
        path: '/home/camp-biji',
        name: 'Biji',
        component: () => import('../home-camp/camp-biji.vue')
      },
      {
        path: '/home/camp-shipin',
        name: 'Shipin',
        component: () => import('../home-camp/camp-shipin.vue')
      },
      {
        path: '/home/camp-huodong',
        name: 'Huodong',
        component: () => import('../home-camp/camp-huodong.vue')
      },
      {
        path: '/home/camp-muying',
        name: 'Muying',
        component: () => import('../home-camp/camp-muying.vue')
      },
      {
        path: '/home/camp-hongbei',
        name: 'Hongbei',
        component: () => import('../home-camp/camp-hongbei.vue')
      },
      
    ]
  },
  {
    path: '/course',
    name: 'Course',
    component: () => import ('../views/Course.vue'),
  },
  {
    path: '/classify',
    name: 'Classify',
    component: () => import ('../views/Classify.vue'),
    children: [
      {
        path: '/classify/classify-camp',
        name: 'Classify-camp',
        component: () => import ('@/components/classify-camp.vue')
      }
    ]
  },
  {
    path: '/person',
    name: 'Person',
    component: () => import ('../views/Person.vue'),
  },
  {
    path: '/detail',
    name: 'Detail',
    component: () => import('@/views/food-detail.vue')
  },
  {
    path: '/menu-search',
    name: 'Menu-search',
    component: () => import ('../views/Menu-search.vue')
  },
  {
    path: '/food-search',
    name: 'Food-search',
    component: () => import ('../views/Food-search.vue')
  },
  {
    path: '/login',
    name: 'Login',
    component: () => import ('../views/Login.vue')
  }
  // {
  //   path: '/about',
  //   name: 'About',
  //   // route level code-splitting
  //   // this generates a separate chunk (about.[hash].js) for this route
  //   // which is lazy-loaded when the route is visited.
  //   component: () => import(/* webpackChunkName: "about" */ '../views/About.vue')
  // }
]

const router = new VueRouter({
  routes
})


router.beforeEach((to,from,next) =>{
  let a = localStorage.getItem('isLogin');
  if(a){

  }else{
    localStorage.setItem('isLogin',JSON.stringify('false'));
  }
  console.log({to,from});
  if(to.path == '/person'){
    // console.log(111,"login");
    console.log(111);
    let flag = JSON.parse(localStorage.getItem("isLogin"));
    console.log(flag);
    if(flag){
      next();
    }else{
      next('/login')
      console.log(222);
    }
  }else{
     next();
  }
 
})

export default router
